//
//  UIBarButtonItem+ButtonItem.m
//  BaiSi
//
//  Created by Sycamore on 16/4/27.
//  Copyright © 2016年 Sycamore. All rights reserved.
//

#import "UIBarButtonItem+ButtonItem.h"

@implementation UIBarButtonItem (ButtonItem)

+ (instancetype)itemWithImage:(UIImage *)image
                highlightedImage:(UIImage *)highImage
                       target:(id)target
                       action:(SEL)action
{
    UIView *contentView = [[UIView alloc]initWithFrame:CGRectZero];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:image forState:UIControlStateNormal];
    [button setImage:highImage forState:UIControlStateHighlighted];
    [button sizeToFit];
    [button addTarget:target  action:action forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:button];
    contentView.bounds = button.bounds;
     return  [[UIBarButtonItem alloc]initWithCustomView:contentView];
}


+ (instancetype)itemWithImage:(UIImage *)image
             selectedImage:(UIImage *)selImage
                       target:(id)target
                       action:(SEL)action
{
    UIView *contentView = [[UIView alloc]initWithFrame:CGRectZero];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:image forState:UIControlStateNormal];
    [button setImage:selImage forState:UIControlStateSelected];
    [button sizeToFit];
    [button addTarget:target  action:action forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:button];
    contentView.bounds = button.bounds;
    return  [[UIBarButtonItem alloc]initWithCustomView:contentView];
}


@end
